<template>
  <van-nav-bar
    title="注册"
    left-text="返回"
    left-arrow
    @click-left="$router.back()"
  />

  <van-field
    v-model="password"
    type="password"
    label="密码"
    placeholder="请输入密码"
  />
  <van-field
    v-model="repassword"
    type="password"
    label="密码验证"
    placeholder="请再次输入密码"
  />
  <van-button round type="danger" @click="submit">确定</van-button>
</template>

<script setup lang="ts">
import { ref, computed } from "vue";
import { UserRegister } from "@/api/api";
import { useRouter, useRoute } from "vue-router";
import { showConfirmDialog } from "vant";
import { showSuccessToast, showFailToast } from "vant";

const router = useRouter();
const route = useRoute();

const password = ref("");
const repassword = ref("");

const tel = route.query.tel;

const submit = () => {
  if (password.value === repassword.value) {
    showConfirmDialog({
      title: "注册成功",
      message: `注册成功，立即去登录？`,
    }).then(async () => {
      const regist = await UserRegister({
        tel: route.query.tel as string,
        password: password.value as string,
      });
      console.log(regist, route.query.tel);
    });
  }
};
</script>

<style lang="scss" scoped>
.van-nav-bar {
  margin-bottom: 2.5rem;
}
.van-button {
  margin-top: 2.5rem;
}
</style>